/**
 * Copyright © 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.cms.guestbook.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.jeeplus.cms.common.CmsConstant;
import com.jeeplus.cms.support.validation.PatternExtend;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.modules.cms.column.entity.CmsColumn;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import java.util.Date;

/**
 * 留言表Entity
 *
 * @author Sawyer
 * @version 2020-11-22
 */
@Getter
@Setter
@ToString
public class CmsGuestbook extends DataEntity<CmsGuestbook> {

    private static final long serialVersionUID = 1L;

    private CmsColumn column;

    @ExcelField(title = "分类编号", align = 2, sort = 2)
    private String contenttypeId;

    @Length(min = 2, max = 255, message = "标题长度必须介于 2 和 255 之间")
    @ExcelField(title = "标题", align = 2, sort = 3)
    private String title;

    @ExcelField(title = "内容", align = 2, sort = 4)
    @PatternExtend(regexp = "^.{3,3000}$", message = "内容最大长度不能超过3000",required = true)
    private String content;

    @Length(min = 1, max = 64, message = "姓名长度必须介于 1 和 64 之间")
    @ExcelField(title = "姓名", align = 2, sort = 5)
    private String name;

    @Email(message = "邮箱无效")
    @ExcelField(title = "邮箱", align = 2, sort = 6)
    private String email;

    @ExcelField(title = "IP", align = 2, sort = 7)
    private String ip;


    @ExcelField(title = "公开标记", align = 2, sort = 8)
    private String openFlag;

    @ExcelField(title = "回复人", align = 2, sort = 9)
    private String replyBy;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ExcelField(title = "回复时间", align = 2, sort = 10)
    private Date replyDate;
    @ExcelField(title = "回复内容", align = 2, sort = 11)
    private String replyContent;
    @ExcelField(title = "置顶权重", align = 2, sort = 12)
    private Integer topWeight;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ExcelField(title = "置顶期限", align = 2, sort = 13)
    private Date topDate;
    @ExcelField(title = "点赞数", align = 2, sort = 14)
    private Integer agree;
    @ExcelField(title = "反对数", align = 2, sort = 15)
    private Integer oppose;

    /**
     * 所属站点
     */
    @NotBlank(message = "所属站点不能为空")
    private String siteId;

    public CmsGuestbook() {
        super();
        this.setIdType(IDTYPE_AUTO);
    }

    public CmsGuestbook(String id) {
        super(id);
    }

    public CmsGuestbook(CmsColumn column) {
        this.column = column;
    }

    /**
     * 初始化数据
     */
    public void init() {
        this.setTopWeight(0);
        this.setTopDate(null == this.getTopDate() ? new Date() : this.getTopDate());
        this.setAgree(0);
        this.setOppose(0);
        this.setOpenFlag(StringUtils.defaultIfBlank(this.getOpenFlag(), CmsConstant.YES));
    }
}
